package org.yx.service.smfr.save_operation;

import org.yx.exception.BizException;
import org.yx.models.SmfrOprDef;
import org.yx.utils.BaseService;
import org.yx.utils.FieldMap;

/**
 * 保存工序
 * @author zxw
 * @since 2018/03/28
**/
public class SmfrSaveOperationService extends BaseService {
	public SmfrSaveOperationOut saveOperation(SmfrSaveOperationIn in) throws Exception {
		checkStringNotBlank(in, "oper,operDesc");

		SmfrOprDef oper = selectWithPk(SmfrOprDef.class, in.getUserOrgCode(), in.getOper());
		if (oper == null) {
			oper = new SmfrOprDef();
			copyProperties(in, oper);
			oper.setOrgCode(in.getUserOrgCode());
			oper.setOperStatus('N');

			insert(oper);
		} else {
			copyProperties(in, oper);

			if (oper.getOperStatus() == 'D') {
				//throw new BizException("SMFR-0001", new FieldMap("oper", oper.getOper()));
			}
			oper.setOperStatus('N');
			
			update(oper);
		}

		SmfrSaveOperationOut out = new SmfrSaveOperationOut();

		return out;
	}
}